package ua.com.fesvlast.hotel.model.commands;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ua.com.fesvlast.hotel.controller.managers.ConfigurationManager;
import ua.com.fesvlast.hotel.controller.managers.MessageManager;
import ua.com.fesvlast.hotel.model.dao.DAOFactory;
import ua.com.fesvlast.hotel.model.enteties.Users;
import ua.com.fesvlast.hotel.model.utils.OrderStatus;

public class ProcessAdminOrdersCommand implements ICommand{
	private String page=null;
	
	
	@Override
	public String execute(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		Users currentUser =(Users)request.getSession().getAttribute("currentUser");
	
		if(currentUser==null  || !currentUser.getUserType().equals("admin")){
			page=ConfigurationManager.getInstance().getProperty(ConfigurationManager.LOGIN_PAGE_PATH);
			return page;
		}
		
		List<Map<String, Object>> list =DAOFactory.getOrdersDAO().getListAdminOrder(OrderStatus.OPENED.toString());
		
		if(list !=null){
			request.setAttribute("list", list);
			page=ConfigurationManager.getInstance().getProperty(ConfigurationManager.ADMIN_LOOK_ORDERS);
		}else{
			
			request.setAttribute("errorMessage", MessageManager.getInstance().getProperty(MessageManager.ORDER_ERROR_MESSAGE));		
			page=ConfigurationManager.getInstance().getProperty(ConfigurationManager.ERROR_PAGE_PATH);
		}
		
		return page;
	}

}
